{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\code\\AppData\\Local\\Temp\\ipykernel_28952\\1674426633.py:29: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  high_temp_df = pd.concat([high_temp_df, high_temp_records], ignore_index=True)\n",
      "C:\\Users\\code\\AppData\\Local\\Temp\\ipykernel_28952\\1674426633.py:30: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  low_temp_df = pd.concat([low_temp_df, low_temp_records], ignore_index=True)\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "import pandas as pd\n",
    "\n",
    "# 指定文件夹路径\n",
    "folder_path = r'C:\\Users\\code\\Desktop\\data'\n",
    "\n",
    "# 获取文件夹中的所有文件\n",
    "file_list = os.listdir(folder_path)\n",
    "\n",
    "# 创建空的DataFrame用于存储高温和低温数据\n",
    "high_temp_df = pd.DataFrame(columns=['日期时间', '温度'])\n",
    "low_temp_df = pd.DataFrame(columns=['日期时间', '温度'])\n",
    "\n",
    "# 遍历每个文件\n",
    "for file_name in file_list:\n",
    "    # 检查文件是否是Excel文件\n",
    "    if file_name.endswith('.xlsx') or file_name.endswith('.xls'):\n",
    "        # 构建完整的文件路径\n",
    "        file_path = os.path.join(folder_path, file_name)\n",
    "        \n",
    "        # 读取Excel文件\n",
    "        df = pd.read_excel(file_path)\n",
    "        \n",
    "        # 筛选温度超过68或低于32的记录\n",
    "        high_temp_records = df[(df['温度'] > 68)]\n",
    "        low_temp_records = df[(df['温度'] < 32)]\n",
    "        \n",
    "        # 将记录添加到对应的DataFrame中\n",
    "        high_temp_df = pd.concat([high_temp_df, high_temp_records], ignore_index=True)\n",
    "        low_temp_df = pd.concat([low_temp_df, low_temp_records], ignore_index=True)\n",
    "\n",
    "# 将高温和低温数据分别保存到Excel文件中\n",
    "high_temp_df.to_excel(r'C:\\Users\\code\\Desktop\\高温.xlsx', index=False)\n",
    "low_temp_df.to_excel(r'C:\\Users\\code\\Desktop\\低温.xlsx', index=False)\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
